package com.fcl.mylibrary.recyclerviewhelper;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.fcl.mylibrary.ImageLoader.ImageLoader;
import com.fcl.mylibrary.R;
import com.fcl.mylibrary.reflect.ViewInjectUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2017/3/20.
 */

public class BaseHolder extends RecyclerView.ViewHolder {

    public View mRootView;
    private HashMap<Integer, View> mFindViews = new HashMap<>();

    public BaseHolder(View itemView) {
        super(itemView);
        this.mRootView = itemView;
        ViewInjectUtils.inject(this, itemView);
    }

    public void setText(int id, String text) {
        TextView textView = (TextView) getView(id);

        textView.setText(text);
    }

    public void setImage(int id, String url) {
        ImageView imageView = (ImageView) getView(id);
        ImageLoader.getInstance().loadImage(url, imageView, true);
    }

    public View getView(int id) {
        View view = null;
        if (mFindViews.get(id) != null) {
            view = mFindViews.get(id);
        } else {
            view = mRootView.findViewById(id);
            mFindViews.put(id, view);
        }
        return view;
    }
}
